package cn.microservices.cloud.gateway.base.enums;

import cn.microservices.cloud.gateway.util.ICacheKey;
import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.TimeUnit;

public enum TokenKey implements ICacheKey {
	TOKEN("token", 2*365, TimeUnit.DAYS);

	private String key;
	private int timeout;
	private TimeUnit unit;

	TokenKey(String key, int timeout, TimeUnit unit) {
		this.key = key;
		this.timeout = timeout;
		this.unit = unit;
	}

	public String getKey() {
		return "app" + SEPARATOR + key;
	}
	
	@Override
	public String getKey(String suffix) {
    	if (StringUtils.isBlank(suffix)) {
    		return "app" + SEPARATOR + key;
		}
		return "app" + SEPARATOR + key + SEPARATOR+suffix;
	}

	public int getTimeout() {
		return timeout;
	}

	public TimeUnit getUnit() {
		return unit;
	}
}
